//
//  MyUITabViewCtrl.m
//  BlockGame
//
//  Created by he weixian on 12-12-11.
//  Copyright (c) 2012年 广州从兴电子开发有限公司. All rights reserved.
//

#import "MyUITabViewCtrl.h"

#import "cocos2d.h"
#import "HelloWorldLayer.h"
#import "DataModel.h"

@interface MyUITabViewCtrl ()
{
    
}

@property(nonatomic,retain) NSMutableDictionary *dic;
@end

@implementation MyUITabViewCtrl
@synthesize dic = _dic;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)dealloc
{
    self.dic = nil;
    [super dealloc];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.dic = [[[NSMutableDictionary alloc] init] autorelease];
    
    [self.dic setObject:@"随便玩玩" forKey:@"0"];
    NSArray *array = [[NSArray alloc] initWithObjects:@"简单",@"普通",@"困难",nil];
    [self.dic setObject:array forKey:@"1"];
    [self.dic setObject:@"最高记录" forKey:@"2"];
    [self.dic setObject:@"背景音乐" forKey:@"3"];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int i = 0;
    if(section == 0)
    {
        i = 1;
    }
    else if(section == 1)
    {
        i = 3;
    }
    else
    {
        i = 1;
    }
    
    return i;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    int section = indexPath.section;
    NSString *s_str = [NSString stringWithFormat:@"%d",section];
    NSObject *obj = [self.dic objectForKey:s_str];
    
    UITableViewCell *cell;
    if(section == 3)
    {
        static NSString *CellIdentifier3 = @"Cell3";
        cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier3];
        if(cell == NULL)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier3] autorelease];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
         cell.textLabel.text = (NSString*)obj;
    }
    else
    {
        static NSString *CellIdentifier = @"Cell";
        cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        
        if(cell == NULL)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        
        if(section == 1)
        {
            NSArray *array = (NSArray*)obj;
            int i = indexPath.row;
            cell.textLabel.text = [array objectAtIndex:i];
        }
        else
        {
            cell.textLabel.text = (NSString*)obj;
        }
        
    }
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */



    CCDirector *director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
    [self.navigationController pushViewController:director_ animated:YES];
    self.navigationController.navigationBarHidden = YES;
    static BOOL isStart = NO;
    if(isStart==NO)
    {
    DataModel *m = [DataModel getModel];
    // Run the intro Scene
    CCScene *scene = [HelloWorldLayer scene];
    HelloWorldLayer *layer = (HelloWorldLayer *) [scene.children objectAtIndex:1];

    UIPanGestureRecognizer *gestureRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePanFrom:)] autorelease];
    [self.view addGestureRecognizer:gestureRecognizer];
    m._gestureRecognizer = gestureRecognizer;

    [director_ pushScene: scene];
        isStart = YES;
    }
}



@end
